<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
     
      <el-form-item label="股票名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入股票名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
    
      <el-form-item label="是否涨停" prop="iszd">
        <el-input
          v-model="queryParams.iszd"
          placeholder="请输入1涨停，0跌停"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="连板数" prop="lianNum">
        <el-input
          v-model="queryParams.lianNum"
          placeholder="请输入连板数"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1是0否" prop="isLian">
        <el-input
          v-model="queryParams.isLian"
          placeholder="请输入1是0否"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:zt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:zt:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:zt:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:zt:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ztList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="股票代码" align="center" prop="code" />
      <el-table-column label="换手率" align="center" prop="hsl" />
      <el-table-column label="量比" align="center" prop="lb" />
      <el-table-column label="流通市值" align="center" prop="ltsz" />
      <el-table-column label="股票名称" align="center" prop="name" />
      <el-table-column label="成交额" align="center" prop="turnover" />
      <el-table-column label="成交量" align="center" prop="volume" />
      <el-table-column label="净流入" align="center" prop="zljlr" />
      <el-table-column label="主力流出" align="center" prop="zllc" />
      <el-table-column label="主力流入" align="center" prop="zllr" />
      <el-table-column label="最新价" align="center" prop="zxj" />
      <el-table-column label="涨跌停" align="center" prop="iszd">
        <template #default="scope">
          <!-- <span :class="{ 'red-text': scope.row.isZt === 1 }">
            {{ scope.row.isZt === 1 ? '涨停' : '未涨停' }}
          </span> -->
          <!-- <el-button plain>
            {{ scope.row.isZt === '1' ? '涨停' : '未涨停' }}
          </el-button> -->
          <template v-if="scope.row.iszd === 1">
            <el-button type="danger">涨停</el-button>
          </template>
          <template v-else>
            <el-button type="primary">跌停</el-button>
          </template>
        </template>
      </el-table-column>
      <el-table-column label="连板数" align="center" prop="lianNum" />
      <el-table-column label="是否连扳" align="center" prop="isLian" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改每日涨停股票对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="ztRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="股票代码，包含字符" prop="code">
          <el-input v-model="form.code" placeholder="请输入股票代码，包含字符" />
        </el-form-item>
        <el-form-item label="换手率" prop="hsl">
          <el-input v-model="form.hsl" placeholder="请输入换手率" />
        </el-form-item>
        <el-form-item label="量比" prop="lb">
          <el-input v-model="form.lb" placeholder="请输入量比" />
        </el-form-item>
        <el-form-item label="流通市值" prop="ltsz">
          <el-input v-model="form.ltsz" placeholder="请输入流通市值" />
        </el-form-item>
        <el-form-item label="股票名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入股票名称" />
        </el-form-item>
        <el-form-item label="" prop="peTtm">
          <el-input v-model="form.peTtm" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="pn">
          <el-input v-model="form.pn" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="state">
          <el-input v-model="form.state" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="成交额" prop="turnover">
          <el-input v-model="form.turnover" placeholder="请输入成交额" />
        </el-form-item>
        <el-form-item label="成交量" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入成交量" />
        </el-form-item>
        <el-form-item label="涨跌额" prop="zd">
          <el-input v-model="form.zd" placeholder="请输入涨跌额" />
        </el-form-item>
        <el-form-item label="涨跌幅" prop="zdf">
          <el-input v-model="form.zdf" placeholder="请输入涨跌幅" />
        </el-form-item>
        <el-form-item label="" prop="zdfD10">
          <el-input v-model="form.zdfD10" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zdfD20">
          <el-input v-model="form.zdfD20" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zdfD5">
          <el-input v-model="form.zdfD5" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zdfD60">
          <el-input v-model="form.zdfD60" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zdfW52">
          <el-input v-model="form.zdfW52" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="zdfY">
          <el-input v-model="form.zdfY" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="振幅" prop="zf">
          <el-input v-model="form.zf" placeholder="请输入振幅" />
        </el-form-item>
        <el-form-item label="助力净流入" prop="zljlr">
          <el-input v-model="form.zljlr" placeholder="请输入助力净流入" />
        </el-form-item>
        <el-form-item label="主力流出" prop="zllc">
          <el-input v-model="form.zllc" placeholder="请输入主力流出" />
        </el-form-item>
        <el-form-item label="主力五日流出" prop="zllcD5">
          <el-input v-model="form.zllcD5" placeholder="请输入主力五日流出" />
        </el-form-item>
        <el-form-item label="主力流入" prop="zllr">
          <el-input v-model="form.zllr" placeholder="请输入主力流入" />
        </el-form-item>
        <el-form-item label="主力五日流入" prop="zllrD5">
          <el-input v-model="form.zllrD5" placeholder="请输入主力五日流入" />
        </el-form-item>
        <el-form-item label="" prop="zsz">
          <el-input v-model="form.zsz" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="最新价" prop="zxj">
          <el-input v-model="form.zxj" placeholder="请输入最新价" />
        </el-form-item>
        <el-form-item label="" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="1涨停，0跌停" prop="iszd">
          <el-input v-model="form.iszd" placeholder="请输入1涨停，0跌停" />
        </el-form-item>
        <el-form-item label="连板数" prop="lianNum">
          <el-input v-model="form.lianNum" placeholder="请输入连板数" />
        </el-form-item>
        <el-form-item label="1是0否" prop="isLian">
          <el-input v-model="form.isLian" placeholder="请输入1是0否" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Zt">
import { listZt, getZt, delZt, addZt, updateZt } from "@/api/web/zt"

const { proxy } = getCurrentInstance()

const ztList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    code: null,
    hsl: null,
    lb: null,
    ltsz: null,
    name: null,
    peTtm: null,
    pn: null,
    speed: null,
    state: null,
    stockType: null,
    turnover: null,
    volume: null,
    zd: null,
    zdf: null,
    zdfD10: null,
    zdfD20: null,
    zdfD5: null,
    zdfD60: null,
    zdfW52: null,
    zdfY: null,
    zf: null,
    zljlr: null,
    zllc: null,
    zllcD5: null,
    zllr: null,
    zllrD5: null,
    zsz: null,
    zxj: null,
    iszd: null,
    lianNum: null,
    isLian: null
  },
  rules: {
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询每日涨停股票列表 */
function getList() {
  loading.value = true
  listZt(queryParams.value).then(response => {
    ztList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    code: null,
    hsl: null,
    lb: null,
    ltsz: null,
    name: null,
    peTtm: null,
    pn: null,
    speed: null,
    state: null,
    stockType: null,
    turnover: null,
    volume: null,
    zd: null,
    zdf: null,
    zdfD10: null,
    zdfD20: null,
    zdfD5: null,
    zdfD60: null,
    zdfW52: null,
    zdfY: null,
    zf: null,
    zljlr: null,
    zllc: null,
    zllcD5: null,
    zllr: null,
    zllrD5: null,
    zsz: null,
    zxj: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    remark: null,
    createBy: null,
    iszd: null,
    lianNum: null,
    isLian: null
  }
  proxy.resetForm("ztRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加每日涨停股票"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getZt(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改每日涨停股票"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["ztRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateZt(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addZt(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除每日涨停股票编号为"' + _ids + '"的数据项？').then(function() {
    return delZt(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/zt/export', {
    ...queryParams.value
  }, `zt_${new Date().getTime()}.xlsx`)
}

getList()
</script>
